from  appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
              "platformName": "Android",
              "deviceName": "emulator-5554",
              "automationName": "uiautomator2",
              "appPackage": "com.achievo.vipshop",
              "appActivity": ".homepage.activity.MainActivity",
              "noReset": True
            }
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        # 隐式等待
        self.driver.implicitly_wait(20)
    #定位元素
    def find_ele(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    # 显示等待
    def find_ele_wait(self,loc):
        ele=WebDriverWait(self.driver,20).until(EC.element_to_be_clickable(loc))
        return ele
    # 退出
    def tui(self):
        self.driver.quit()
    # 截图
    def jietu(self,name):
        self.driver.save_screenshot(name)
